package com.meihua.shellapp.adapter.personalcenter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.meihua.shellapp.R;
import com.meihua.shellapp.activity.wallet.IncomeDetailActivity;
import com.meihua.shellapp.activity.wallet.SalaryDetailsActivity;
import com.meihua.shellapp.activity.wallet.WithdrawalsDetailActivity;
import com.meihua.shellapp.databean.BillDataBean;
import com.meihua.shellapp.utils.DateUtils;

import java.util.List;

public class CurrentMonthFragmentAdapter extends RecyclerView.Adapter<CurrentMonthFragmentAdapter.OrderHandler> {
    private List<BillDataBean> mList;
    private Context mContext;
    private int type;//1.月收入的   2.提现记录的

    public CurrentMonthFragmentAdapter(Context context, List<BillDataBean> list, int type) {
        mContext = context;
        mList = list;
        this.type = type;
    }

    @Override
    public OrderHandler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wallet_in_lv, null);
        // 实例化viewholder
        OrderHandler viewHolder = new OrderHandler(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(OrderHandler holder, final int position) {
        holder.tv_time.setText(DateUtils.getInstance().getTimeYMDHM(mList.get(position).getTime()));
        holder.tv_car_quan.setText(mList.get(position).getMoney());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (type == 1) {
                    mContext.startActivity(new Intent(mContext, IncomeDetailActivity.class)
                            .putExtra("type", mList.get(position).getType())
                            .putExtra("id", mList.get(position).getId())
                    );
                } else if (type == 2) {
                    mContext.startActivity(new Intent(mContext, SalaryDetailsActivity.class)
                            .putExtra("id", mList.get(position).getId())
                    );
                } else {
                    mContext.startActivity(new Intent(mContext, WithdrawalsDetailActivity.class)
                            .putExtra("id", mList.get(position).getId())
                    );
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    public class OrderHandler extends RecyclerView.ViewHolder {
        TextView tv_time, tv_car_quan;

        public OrderHandler(View itemView) {
            super(itemView);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv_car_quan = itemView.findViewById(R.id.tv_car_quan);
        }
    }
}